#include "hzpch.h"
#include "OpenGLContext.h"

#include "glad/glad.h"
#include <GLFW/glfw3.h>


#define SPDLOG_WCHAR_TO_UTF8_SUPPORT 
namespace Hazel{
    OpenGLContext::OpenGLContext(GLFWwindow *windowHandle)
        :m_WindowHandle(windowHandle)
    {
        if(!windowHandle)
        {
            HZ_CORE_ERROR("windowHandle is NULL!");
        }
    }

    void OpenGLContext::Init()
    {
        HZ_PROFILE_FUNC();
        
        glfwMakeContextCurrent(m_WindowHandle);
        int status=gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
        if(!status)
        {
            HZ_CORE_ERROR("fail to initialize GLAD!");
        }
        std::cout<<glGetString(GL_VENDOR)<<'\n';
        std::stringstream ss;
        ss<<glGetString(GL_VENDOR);
        ss<<' ';
        ss<<glGetString(GL_RENDERER);
        HZ_CORE_INFO("OpenGL Render: {0}",ss.str());

        
    }
    void OpenGLContext::SwapBuffers()
    {
        HZ_PROFILE_FUNC();

        glfwSwapBuffers(m_WindowHandle);
    }
}